﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Citi.PTSConsolidation.Domain;
using Citi.PTSConsolidation.WebUi.Models;

namespace Citi.PTSConsolidation.WebUi.Controllers
{
    public class FinancialTypeController : Controller
    {
        public ActionResult Index()
        {
            var financialTypes = new FinancialType().SelectAll<FinancialType>().OrderBy(x=> x.AccountLevel1);
            return View(FinancialTypeModel.CreateModel(financialTypes));
        }

        public ActionResult Edit(int id)
        {
            var financialType = new FinancialType().SelectById<FinancialType>(id);
            return View(FinancialTypeModel.CreateModel(financialType));
        }

        [HttpPost]
        public ActionResult Edit(FinancialTypeModel model)
        {
            var financialType = new FinancialType().SelectById<FinancialType>(model.Id);

            financialType.LineType = model.LineType;
            financialType.Save(financialType);

            return RedirectToAction("Index");
        }
    }
}
